package cn.edu.thu.tsquality.adaptor.single;

import cn.edu.thu.tsquality.core.common.algorithm.IAlgorithm;
import cn.edu.thu.tsquality.core.common.datasource.CsvDataSource;
import cn.edu.thu.tsquality.core.common.datasource.IDataSource;
import cn.edu.thu.tsquality.core.common.table.Table;

import java.io.IOException;
import java.util.List;

/**
 * Created by wangyihan  on 2018/4/22 下午4:42.
 * E-mail address is yihanwang22@163.com.
 * Copyright © 2017 wangyihan. All Rights Reserved.
 *
 * @author wangyihan
 */
public class SingleAdaptor {
  private IAlgorithm algorithm;

  public void setAlgorithm(IAlgorithm algorithm) {
    this.algorithm = algorithm;
  }

  public void run(String inputFilePath, String outputFilePath, final List<String> usedAttrs) throws IOException {
    IDataSource dataSource = new CsvDataSource(inputFilePath);
    if (usedAttrs != null) {
      dataSource.filter(usedAttrs.toArray(new String[]{}));
    }
    Table dataTable = dataSource.read();
    Table resultTable = this.algorithm.run(dataTable);
    IDataSource resultSource = new CsvDataSource(outputFilePath);
    resultSource.write(resultTable);
  }
}
